﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Zampolit
{
    public class Search
    {
        public int l; //переменная длинны списка
        private int i;
        private string a;
       // private string name = "big";
        public string aPath = Environment.CurrentDirectory;

        public void SearchFile(string fileName){
            
            DirectoryInfo dir = new DirectoryInfo(@aPath);
            DirectoryInfo[] dirf = dir.GetDirectories();
            FileInfo[] fileinf = dir.GetFiles();
            foreach (DirectoryInfo x in dirf)
            {
                Console.Out.WriteLine(x.Name);
                FileInfo[] fileinf1 = x.GetFiles();//поиск в папках
                foreach (FileInfo inf in fileinf1)
                {
                    if (fileName == inf.Name.Substring(0, (inf.Name.Length - inf.Extension.Length)))
                        Console.Out.WriteLine("[Файл найден]");
                }
            }
            foreach (FileInfo inf in fileinf)//поиск в корне
            {
                if (fileName == inf.Name.Substring(0, (inf.Name.Length - inf.Extension.Length)))
                    Console.Out.WriteLine("[Файл найден]");
            }

            l = dirf.Length;

            Console.Out.WriteLine("\n\nВ них находятся подпапки: \n\n");
            a = "";
            for (i = 1; i < l; i++)//поиск в подпапках
            {
                    DirectoryInfo[] udir = dirf[i].GetDirectories();
                    foreach (DirectoryInfo xx in udir)
                    {
                        Console.Out.WriteLine(xx.Name);
                        FileInfo[] fileinfo = xx.GetFiles();
                        foreach (FileInfo inf in fileinfo)
                        {
                            if (fileName == inf.Name.Substring(0, (inf.Name.Length - inf.Extension.Length)))
                                Console.Out.WriteLine("[Файл найден]");
                        }
                        
                    }
                    
            }

        }
    }
}
